package sedev.shopping.business;

import sedev.shopping.data.NhomSanPhamDAO;
import sedev.shopping.entities.ListNhomSanPham;
import sedev.shopping.entities.NhomSanPham;
import sedev.shopping.util.Paging;
import sedev.shopping.util.SedevUtil;

public class NhomSanPhamService {
	
	public static boolean addData(NhomSanPham data){
		NhomSanPhamDAO dao = new NhomSanPhamDAO();
		return dao.addData(data);
	}
	
	public static boolean updateData(NhomSanPham data){
		NhomSanPhamDAO dao = new NhomSanPhamDAO();
		return dao.updateData(data);
	}
	
	public static boolean removeData(long id){
		NhomSanPhamDAO dao = new NhomSanPhamDAO();
		return dao.removeData(id);
	}
	
	public static NhomSanPham getData(long id){
		NhomSanPhamDAO dao = new NhomSanPhamDAO();
		return dao.getData(id);		
	}
	
	public static ListNhomSanPham getListDataByAll(SedevUtil.ModeDisplay mode_display){
		StringBuilder field = new StringBuilder();
		field.append(NhomSanPham.Properties.id.name());
		field.append(",").append(NhomSanPham.Properties.nhom_san_pham_id.name());
		field.append(",").append(NhomSanPham.Properties.ten.name());
		field.append(",").append(NhomSanPham.Properties.thuoc_tinh.name());
		field.append(",").append(NhomSanPham.Properties.ngay_dang.name());
	
		StringBuilder condition = new StringBuilder();
		condition.append("1 AND 1");		
		switch (mode_display) {
			case Display:
				condition.append(" AND ").append(NhomSanPham.Properties.hien_thi.name()).append("= 1");
				break;
			case Hide:
				condition.append(" AND ").append(NhomSanPham.Properties.hien_thi.name()).append("= 0");
				break;
			default:
				break;
		}
		
		StringBuilder order = new StringBuilder();
		order.append(NhomSanPham.Properties.ngay_dang.name()).append(" ").append(SedevUtil.Order.ASC);
		Paging paging = new Paging();
		
		NhomSanPhamDAO dao = new NhomSanPhamDAO();
		return dao.getListData(field.toString(), condition.toString(), order.toString(), paging);
	}
	
	public static ListNhomSanPham getListDataByProductGroup(long nhom_san_pham_id, SedevUtil.ModeDisplay mode_display){

		StringBuilder field = new StringBuilder();
		field.append(NhomSanPham.Properties.id.name());		
		field.append(",").append(NhomSanPham.Properties.ten.name());
		field.append(",").append(NhomSanPham.Properties.ngay_dang.name());
	
		StringBuilder condition = new StringBuilder();
		condition.append("1 AND 1");
		condition.append(" AND ").append(NhomSanPham.Properties.nhom_san_pham_id.name()).append("=").append(nhom_san_pham_id);
		switch (mode_display) {
			case Display:
				condition.append(" AND ").append(NhomSanPham.Properties.hien_thi.name()).append("= 1");
				break;
			case Hide:
				condition.append(" AND ").append(NhomSanPham.Properties.hien_thi.name()).append("= 0");
				break;
			default:
				break;
		}
		
		StringBuilder order = new StringBuilder();
		order.append(NhomSanPham.Properties.ngay_dang.name()).append(" ").append(SedevUtil.Order.ASC);
		Paging paging = new Paging();
		
		NhomSanPhamDAO dao = new NhomSanPhamDAO();
		return dao.getListData(field.toString(), condition.toString(), order.toString(), paging);
	}
	
	public static ListNhomSanPham getListDataByDiffId(long id, SedevUtil.ModeDisplay mode_display){
		StringBuilder field = new StringBuilder();
		field.append(NhomSanPham.Properties.id.name());		
		field.append(",").append(NhomSanPham.Properties.ten.name());
		field.append(",").append(NhomSanPham.Properties.ngay_dang.name());
	
		StringBuilder condition = new StringBuilder();
		condition.append("1 AND 1");
		condition.append(" AND ").append(NhomSanPham.Properties.id.name()).append("!=").append(id);
		condition.append(" AND ").append(NhomSanPham.Properties.nhom_san_pham_id.name()).append("!=").append(id);
		switch (mode_display) {
			case Display:
				condition.append(" AND ").append(NhomSanPham.Properties.hien_thi.name()).append("= 1");
				break;
			case Hide:
				condition.append(" AND ").append(NhomSanPham.Properties.hien_thi.name()).append("= 0");
				break;
			default:
				break;
		}
		
		StringBuilder order = new StringBuilder();
		order.append(NhomSanPham.Properties.ngay_dang.name()).append(" ").append(SedevUtil.Order.ASC);
		Paging paging = new Paging();
		
		NhomSanPhamDAO dao = new NhomSanPhamDAO();
		return dao.getListData(field.toString(), condition.toString(), order.toString(), paging);
	}
}
